import java.sql.Connection;
import java.sql.Statement;

import util.IdUtil;
import util.JdbcUtil;

import common.Constants;

import exception.SystemException;

public class TestData {
	
	//创建测试数据 建表脚本为sample.sql
	public static void main(String[] args) {
		Connection conn = JdbcUtil.getConnection(Constants.ORACLE_DB_URL, "modudf_test", "modudf_test");
		Statement stmt = null;
		try {
			conn.setAutoCommit(false);
			stmt = conn.createStatement();
			for (int i = 0; i < 10000; i++) {
				String empno = IdUtil.getInstanse().getUID();
				String checkno = "checkno" + i;
				String name = "name" + i;
				String deptno = "dept" + (int)(Math.random()*10);
				String regioncode = "regioncode" + i;
				String fcd = "fcd" + i;
				String fcu = "fcu" + i;
				String lcd = "lcd" + i;
				String lcu = "lcu" + i;
				String valid = "Y";
				String agent_type = "agent_type" + i;
				String emp_type = "emp_type" + i;
				String leave_date = "leave_date" + i;
				String memorized = "Y";
				String default_group_seq = "dgs" + i;
				String eff_date = "eff_date" + i;
				String rank = "rank" + i;
				String sex = i % 2 == 0 ? "male" : "female";
				String post_lvl = "post_lvl" + i;
				String birth_date = "birth_date" + i;
				String worksheet_seq = String.valueOf(100 + (int)(Math.random()*20));
				String worksheet_eff_date = "wed" + i;
				String emp_idno = "emp_idno" + i;
				String sql = "insert into modudf_test.AFCS_AGENT values ('" + empno + "'" ;
				sql += ", '" + checkno + "'";
				sql += ", '" + name + "'";
				sql += ", '" + deptno + "'";
				sql += ", '" + regioncode + "'";
				sql += ", '" + fcd + "'";
				sql += ", '" + fcu + "'";
				sql += ", '" + lcd + "'";
				sql += ", '" + lcu + "'";
				sql += ", '" + valid + "'";
				sql += ", '" + agent_type + "'";
				sql += ", '" + emp_type + "'";
				sql += ", '" + leave_date + "'";
				sql += ", '" + memorized + "'";
				sql += ", '" + default_group_seq + "'";
				sql += ", '" + eff_date + "'";
				sql += ", '" + rank + "'";
				sql += ", '" + sex + "'";
				sql += ", '" + post_lvl + "'";
				sql += ", '" + birth_date + "'";
				sql += ", '" + worksheet_seq + "'";
				sql += ", '" + worksheet_eff_date + "'";
				sql += ", '" + emp_idno + "'";
				sql += ")";
				System.out.println(sql);
				stmt.addBatch(sql);
				if (i % 100 == 0) {
					stmt.executeBatch();
					stmt.clearBatch();
				}
			}
			stmt.addBatch("ANALYZE TABLE modudf_test.AFCS_AGENT COMPUTE STATISTICS");
			stmt.executeBatch();
			JdbcUtil.commitConnection(conn);
		} catch (Exception e) {
			e.printStackTrace();
			throw new SystemException(e);
		} finally {
			try {
				JdbcUtil.closeConnection(conn);
			} catch (Exception e) {
				e.printStackTrace();
				throw new SystemException(e);
			}
		}
	}
}
